import { Component } from '@angular/core';
import { NavController, ModalController, LoadingController } from 'ionic-angular';
import { QuestionPage } from '../question/question';
import { BaseUI } from '../../common/baseui';
import { RestProvider } from '../../providers/rest/rest';
import { DetailsPage } from '../details/details';



@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage extends BaseUI {
  feeds: any = [];
  errMessage: string;
  constructor(
    public navCtrl: NavController,
    private modalCtrl: ModalController,
    private rest: RestProvider,
    private loadingCtrl: LoadingController) {
    super();
  }

  ionViewDidLoad(){
    this.getFeeds();
  }
  goToQuestion() {
    let modal = this.modalCtrl.create(QuestionPage);
    modal.present();
  }
  goToChart() {
    this.navCtrl.parent.select(2);
  }

  getFeeds() {
    var loading = super.showLoading(this.loadingCtrl, "加载中...")
    this.rest.getFeeds()
      .subscribe(data => {
          this.feeds = data;
          loading.dismiss();
      }, error => this.errMessage = <any>error);
  }
    goDetail(id){
      this.navCtrl.push(DetailsPage,{
        id : id
      });
    }
}
